home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / incl / LEDA.020+881 / impl / p_aux_heap.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  2.1 KB  |  90 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  p_aux_heap.h
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #ifndef LEDA_PAIRING_AUX_HEAP_H
  16. #define LEDA_PAIRING_AUX_HEAP_H
  17.  
  18. #include <LEDA/impl/p_heap.h>
  19.  
  20. // by Markus Neukirch
  21. //
  22. // Implementation following John T. Stasko and Jeffrey Scott Vitter
  23. // ( Communications of the ACM   March 1987 Volume 30 Number 3   S. 234-240 )
  24.  
  25.  
  26.  
  27. class p_aux_heap:public p_heap
  28. {
  29.     
  30.     ph_item* head,*minptr;
  31.     int item_count;
  32.  
  33.     virtual int cmp(GenPtr x, GenPtr y) const {return compare (x,y);}
  34.  
  35.     virtual void print_key(GenPtr)  const {}
  36.     virtual void print_inf(GenPtr)  const {}
  37.  
  38.     virtual void clear_key(GenPtr&)  const {}
  39.     virtual void clear_inf(GenPtr&)  const {}
  40.     virtual void copy_key(GenPtr&)   const {}
  41.     virtual void copy_inf(GenPtr&)   const {}
  42.  
  43.     virtual int  int_type() const { return 0; }
  44.  
  45.     void do_copy(ph_item*,ph_item*,bool);
  46.     ph_item* twopass(ph_item*);
  47.     ph_item* multipass(ph_item*);
  48.     
  49. public:
  50.     
  51.     
  52.     p_aux_heap();
  53.  
  54.     p_aux_heap(int)     { error_handler(1,"no p_heap(int) constructor");}
  55.         p_aux_heap(int,int) { error_handler(1,"no p_heap(int,int) constructor");}
  56.  
  57.     p_aux_heap(const p_aux_heap& init);        // construct
  58.  
  59.     p_aux_heap& operator=(const p_aux_heap&);
  60.     ~p_aux_heap() {clear();}
  61.  
  62.     ph_item* insert(GenPtr,GenPtr);
  63.     void decrease_key(ph_item*,GenPtr);
  64.     ph_item* find_min() const
  65.         {return minptr;}
  66.     void delete_min_multipass();            // auxiliary version
  67.     void delete_min_twopass();            // auxiliary version
  68.  
  69.     GenPtr key(ph_item* x) const {return x->key;}
  70.     GenPtr inf(ph_item* x) const {return x->inf;}
  71.     
  72.     void change_inf(ph_item* x,GenPtr inf)
  73.         {clear_inf(x->inf);copy_inf(inf);x->inf=inf;}
  74.  
  75.     void del_item(ph_item* x)
  76.         {decrease_key(x,minptr->key);delete_min_twopass();}
  77.     
  78.     void clear() 
  79.         {p_heap::clear();item_count=0;}
  80.     int  size() const { return item_count;}
  81.     int  empty() const {return item_count;}
  82.  
  83.         
  84. };    
  85.  
  86.  
  87.  
  88. #endif
  89.